/*	Interactive Gravitational Simulator
	Project: IGS Core
	File: Snapshot.cpp
	Author: Mike Bantegui <mbante2@gmail.com>, Hofstra University 
	Copyright (C) 2012 - 2013 Mike Bantegui

	This file is part of the IGS software package for simulating
	the N-Body problem in real-time. This was developed as part
	of a departmental honors thesis project at Hofstra University
	in the Spring 2012 semester.

	IGS is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	IGS is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#include "Body.h"
#include "Snapshot.h"
#include "ViewNode.h"

namespace IGS
{

// Creates a Snapshot with the specified contents
Snapshot::Snapshot(const Body *bodies, const int n, const double mass,
	const Dynamics &dynamics, const std::shared_ptr<ViewNode> tree) : N(n),
	_Mass(mass), Bodies(new PhasePoint[n]), _Dynamics(dynamics), _Tree(tree)
{
	for (int i = 0; i < n; i++)
		Bodies[i] = bodies[i];
}

// Destructs the Snapshot
Snapshot::~Snapshot()
{
	delete[] Bodies;
}

const std::shared_ptr<ViewNode> Snapshot::Tree() const
{
	return _Tree;
}

// Gets the kinetic energy of the Snapshot
const double Snapshot::KineticEnergy() const
{
	return _Dynamics.Kinetic;
}

// Gets the potential energy of the Snapshot
const double Snapshot::PotentialEnergy() const
{
	return _Dynamics.Potential;
}

// Gets the total energy of the Snapshot
const double Snapshot::TotalEnergy() const
{
	return KineticEnergy() + PotentialEnergy();
}

// Gets the maximum distance of a body from the origin
const double Snapshot::MaxDistance() const
{
	return _Dynamics.MaxDistance;
}

// Gets the maximum velocity of a body in the Snapshot
const double Snapshot::MaxVelocity() const
{
	return _Dynamics.MaxVelocity;
}

// Gets the maximum momentum of a body in the Snapshot
const double Snapshot::MaxMomentum() const
{
	return _Dynamics.MaxMomentum;
}

// Gets the maximu mass of a body in the Snapshot
const double Snapshot::MaxMass() const
{
	return _Dynamics.MaxMass;
}

// Gets the center of mass of the Snapshot
const Vector Snapshot::CenterOfMass() const
{
	return _Dynamics.CenterOfMass;
}

// Gets the center of momentum of the Snapshot
const Vector Snapshot::CenterOfMomentum() const
{
	return _Dynamics.CenterOfMomentum;
}

// Gets the angular momentum of the Snapshot
const Vector Snapshot::AngularMomentum() const
{
	return _Dynamics.AngularMomentum;
}

// Get the angular velocity of the Snapshot
const Vector Snapshot::AngularVelocity() const
{
	return _Dynamics.AngularVelocity;
}

// Gets the total force of the Snapshot
const Vector Snapshot::TotalForce() const
{
	return _Dynamics.TotalForce;
}

// Gets the minimum boundary of the Snapshot
const Vector Snapshot::MinBound() const
{
	return _Dynamics.MinBound;
}

// Gets the maximum boundary of the Snapshot
const Vector Snapshot::MaxBound() const
{
	return _Dynamics.MaxBound;
}

// Gets the size of the Snapshot
const int Snapshot::Size() const
{
	return N;
}

// Gets the total mass of the Snapshot
const double Snapshot::Mass() const
{
	return _Mass;
}

// Gets an immutable reference to the i-th body in the Snapshot
const PhasePoint &Snapshot::operator[](const int i) const
{
	return Bodies[i];
}

}
